package com.home.school.model;

import lombok.Data;
import lombok.ToString;

/**
 * @author cyt
 * @create 2020-07-07 18:33
 */
@ToString
@Data
public class R {
    private Boolean success;
    private Integer code;
    private String message;
    private Object data;
    private long count;
    private long page;
    private long current;
    private long totalPage;
    /**
     * 把构造方法私有
     */
    private R() {
    }

    /**
     * 成功静态方法
     *
     * @return
     */
    public static R ok() {
        R r = new R();
        r.setSuccess(true);
        r.setCode(ResultCode.SUCCESS.getCode());
        r.setMessage("成功");
        return r;
    }

    /**
     * 失败静态方法
     *
     * @return
     */
    public static R error() {
        R r = new R();
        r.setSuccess(false);
        r.setCode(ResultCode.ERROR.getCode());
        r.setMessage("失败");
        return r;
    }
    public static R error(String msg) {
        R r = new R();
        r.setSuccess(false);
        r.setCode(ResultCode.ERROR.getCode());
        r.setMessage(msg);
        return r;
    }
    public R success(Boolean success) {
        this.setSuccess(success);
        return this;
    }

    public R message(String message) {
        this.setMessage(message);
        return this;
    }

    public R code(Integer code) {
        this.setCode(code);
        return this;
    }

    public R data( Object value) {
        this.data = value;
        return this;
    }

    public R addCount( long value) {
        this.count = value;
        return this;
    }

    public R addPage( long value) {
        this.page = value;
        return this;
    }
    public R addCurrent( long value) {
        this.current = value;
        return this;
    }
    public R addTotalPage( long value) {
        this.totalPage = value;
        return this;
    }

}
